var api = require('../../utils/api.js');
var app = getApp();

Page({
  data: {
    MemberGender: '0',
    MemberMobile:'',
    MemberTelephone:'',
    MemberEmail:'',
    MemberQQ:'',

    modalHidden:true,
  },

  onLoad: function (options) {
    var that = this;
    var MemberGender = wx.getStorageSync('MemberGender'),
        MemberMobile = wx.getStorageSync('MemberMobile'),
        MemberTelephone = wx.getStorageSync('MemberTelephone'),
        MemberEmail = wx.getStorageSync('MemberEmail'),
        MemberQQ = wx.getStorageSync('MemberQQ');
        MemberMobile == null ? '' : MemberMobile;
    that.setData({
        MemberGender: MemberGender,
        MemberMobile: MemberMobile,
        MemberTelephone: MemberTelephone,
        MemberEmail: MemberEmail,
        MemberQQ: MemberQQ
    });
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: app.globalData.XcxThemeColor
    });
  },

  MemberGender: function (e) {
    var that = this;
    that.setData({
      MemberGender: e.detail.value
    })
  },

  MemberMobile: function (e) {
    var that = this;
    that.setData({
      MemberMobile: e.detail.value
    })
  },

  MemberTelephone: function (e) {
    var that = this;
    that.setData({
      MemberTelephone: e.detail.value
    })
  },
  
  MemberEmail: function (e) {
    var that = this;
    that.setData({
      MemberEmail: e.detail.value
    })
  },

  MemberQQ: function (e) {
    var that = this;
    that.setData({
      MemberQQ: e.detail.value
    })
  },
  
  //显示
  modalTap:function(e){
     var that = this;
     that.setData({
        modalHidden:false
     })
  },
  
  //隐藏并保存
  modalChange: function (e) { 
    var that = this;
    that.modifyMemberInfo();
    that.setData({
      modalHidden: true
    })
  },
  
  //隐藏
  modalCancel: function (e) {
    var that = this;
    that.setData({
      modalHidden: true
    })
  },

  modifyMemberInfo:function(){
     var that = this;
     var params = {
        MemberGender: that.data.MemberGender,
        MemberMobile: that.data.MemberMobile,
        MemberTelephone: that.data.MemberTelephone,
        MemberEmail: that.data.MemberEmail,
        MemberQQ: that.data.MemberQQ
     }
     api.modifyMemberInfo(params).then(function(res){
          if(res.Status==1){
            wx.showToast({
              title: res.Message,
              icon: 'success',
              duration: 2000
            })
            wx.setStorageSync('MemberGender', res.Data.MemberGender);
            wx.setStorageSync('MemberMobile', res.Data.MemberMobile);
            wx.setStorageSync('MemberTelephone', res.Data.MemberTelephone);
            wx.setStorageSync('MemberEmail', res.Data.MemberEmail);
            wx.setStorageSync('MemberQQ', res.Data.MemberQQ);
            that.setData({
              MemberGender: res.Data.MemberGender,
              MemberMobile: res.Data.MemberMobile,
              MemberTelephone: tres.Data.MemberTelephone,
              MemberEmail: tres.Data.MemberEmail,
              MemberQQ: res.Data.MemberQQ
            })
          }else{
            wx.showToast({
              title: res.Message,
              icon: 'success',
              duration: 2000
            })
          }
     });
  } 
})